package com.gongren.project.job.odd;

import com.alibaba.dubbo.config.annotation.Reference;
import com.gongren.project.odd.job.rpc.api.service.taskRpc.IJobRpcTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Author houzhong
 * @Date 2017/9/1 12:39
 */
@Component("jobTask")
public class JobTask {

    private static final Logger LOGGER = LoggerFactory .getLogger(JobTask.class);

    @Reference
    private IJobRpcTaskService jobRpcTaskService;

    /**
     * 每30分钟执行一次，打零工招聘服务
     * @throws Exception
     */
    @Transactional
    //@Scheduled(cron = "0 0/30 * * * ? ")
    public void excuteJobTaskToOverdueTask(){

        LOGGER.info("jobTask and excuteJobTaskToOverdueTask start");
        try {
            jobRpcTaskService.findAllExcuteJobTaskToOverdueTask();

            LOGGER.info("jobTask and excuteJobTaskToOverdueTask end");
        } catch (Exception e) {
            LOGGER.error("jobTask and excuteJobTaskToOverdueTask：{}", e);
        }
    }

    /**
     * 每30分钟执行一次，给代理推送一条消息
     * @throws Exception
     */
    @Transactional
    //@Scheduled(cron = "0 0/30 * * * ? ")
    public void excuteNotAgentTask(){
        LOGGER.info("jobTask and excuteNotAgentTask start");
        try {
            jobRpcTaskService.findAllExcuteNotAgentTask();

            LOGGER.info("jobTask and excuteNotAgentTask end");
        } catch (Exception e) {
            LOGGER.error("jobTask and excuteNotAgentTask：{}", e);
        }
    }

}
